<?php

if ( ! function_exists('buildSuccess'))
{
    function buildSuccess($data = [])
    {
        return ['status' => 'ok', 'data' => $data];
    }
}

if ( ! function_exists('buildError'))
{
    function buildError($error_msg)
    {
        if ($error_msg instanceof \Exception) {
            if (\Input::get('debug') !== null) {
                $error_msg = sprintf('code:%s,file:%s,line:%s,message:%s', $error_msg->getCode(),  $error_msg->getFile(), $error_msg->getLine(), $error_msg->getMessage());
            } else {
                $error_msg = $error_msg->getMessage();
            }
        }
        return ['status' => 'error', 'message' => $error_msg];
    }
}

function generatePassword()
{
    $chars = array_merge(range(0, 9), range('a', 'z'));
    shuffle($chars);
    $password = '';

    for ($i = 0; $i < 8; $i++) {
        $password .= $chars[$i];
    }

    return $password;
}